/*
 * @Description: 
 * @Author: paddies
 * @Date: 2024-11-15 23:01:21
 * @LastEditors: paddies
 * @LastEditTime: 2025-04-17 16:06:57
 * @FilePath: /shared_components/lib/luntai-components/new-login-panel/controller.dart
 */

import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:shared_components/build-button/buildButton.dart';
import 'package:shared_components/build-common/buildCommon.dart';
import 'package:shared_components/build-upload/buildUpload.dart';
import 'package:shared_components/luntai-components/new-login-panel/components/buildBanner.dart';
import 'package:shared_components/luntai-components/new-login-panel/components/buildCommon.dart';
import 'package:shared_components/luntai-components/new-login-panel/state.dart';

class NewLoginPanelPageController extends GetxController {
  final NewLoginPanelPageState state = NewLoginPanelPageState();

  final TextEditingController loginPhoneInputController =
      TextEditingController();

  //统一信用代码输入控制器
  final TextEditingController registerCertificateCodeInputController =
      TextEditingController();
  //公司名称输入控制器
  final TextEditingController registerStoreNameInputController =
      TextEditingController();

  //公司地址输入控制器
  final TextEditingController registerAddressInputController =
      TextEditingController();
  //身份证输入控制器
  final TextEditingController registerIdNumberInputController =
      TextEditingController();

  //身份证输入控制器
  final TextEditingController registerUserNameInputController =
      TextEditingController();
//车牌输入控制器
  final TextEditingController registerCarNumberInputController =
      TextEditingController();

  final TextEditingController registerDriverNameInputController =
      TextEditingController();

  final TextEditingController registerPhoneInputController =
      TextEditingController();

  // 切换勾选已读
  void changeRead() {
    state.isRead.value = !state.isRead.value;
  }

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
  }

  //处理密码登录逻辑
  void handleLogin(
      {required Function loginSuccess,
      required BuildContext context,
      required String appType,
      required Function registerAPI,
      required Function({String userAccount, String userType})
          rejectAndRegisterAPI,
      required dynamic Function({String mobile}) sendRegisterCodeAPI,
      required Function({String userAccount, String password})
          loginAPI}) async {
    var userAccount = state.loginPhone.value;
    var password = state.loginPassword.value;

    if (userAccount.isEmpty) {
      EasyLoading.showToast("请输入手机号");
      return;
    }

    if (password.isEmpty) {
      EasyLoading.showToast("请输入密码");
      return;
    }

    //检查同意按钮
    var isRead = state.isRead.value;
    if (!isRead) {
      EasyLoading.showToast("请勾选同意按钮");
      return;
    }

    var data = await loginAPI(userAccount: userAccount, password: password);
    if (data == 600) {
      openRegister(
          context: context,
          appType: appType ?? "user",
          registerAPI: registerAPI,
          loginSuccess: loginSuccess,
          loginAPI: loginAPI,
          operationType: 'addToInfo',
          userAccount: userAccount,
          rejectAndRegisterAPI: rejectAndRegisterAPI,
          sendRegisterCodeAPI: sendRegisterCodeAPI);
      return;
    }
    // var data = await doLogin(userAccount: userAccount, password: password);
    resetLoginInfo();
    //抛出给使用者处理逻辑
    loginSuccess(data);
    // GlobalPrefs.saveToken(data["access_token"]);
    // Get.offUntil(MaterialPageRoute(builder: (context) {
    //   return LayoutPage();
    // }), (route) => false);
  }

  //重置登录信息
  void resetLoginInfo() {
    state.loginPhone.value = "";
    state.loginPassword.value = "";
    state.isRead.value = false;
    loginPhoneInputController.text = "";
  }

  openRegister(
      {required BuildContext context,
      required String appType,
      String userAccount = '',
      String requestBaseUrl = '',
      String operationType = 'default', //操作方式，默认、补充(addToInfo)
      required Function({String userAccount, String password}) loginAPI,
      required Function registerAPI,
      required Function loginSuccess,
      required Function({String userAccount, String userType})
          rejectAndRegisterAPI,
      required Function({String mobile}) sendRegisterCodeAPI}) {
    resetRegisterInfo();
    if (appType == 'user') {
      buildUserRegister(
          context: context,
          appType: appType,
          loginAPI: loginAPI,
          requestBaseUrl: requestBaseUrl,
          registerAPI: registerAPI,
          loginSuccess: loginSuccess,
          sendRegisterCodeAPI: sendRegisterCodeAPI);
    }
    if (appType == 'supplier') {
      buildSupplierRegister(
          context: context,
          appType: appType,
          loginAPI: loginAPI,
          requestBaseUrl: requestBaseUrl,
          registerAPI: registerAPI,
          loginSuccess: loginSuccess,
          operationType: operationType,
          userAccount: userAccount,
          rejectAndRegisterAPI: rejectAndRegisterAPI,
          sendRegisterCodeAPI: sendRegisterCodeAPI);
    }

    if (appType == 'worker') {
      buildWorkerRegister(
          context: context,
          appType: appType,
          loginAPI: loginAPI,
          requestBaseUrl: requestBaseUrl,
          registerAPI: registerAPI,
          loginSuccess: loginSuccess,
          operationType: operationType,
          userAccount: userAccount,
          rejectAndRegisterAPI: rejectAndRegisterAPI,
          sendRegisterCodeAPI: sendRegisterCodeAPI);
    }

    if (appType == 'business') {
      buildBusinessRegister(
          context: context,
          appType: appType,
          loginAPI: loginAPI,
          requestBaseUrl: requestBaseUrl,
          registerAPI: registerAPI,
          loginSuccess: loginSuccess,
          operationType: operationType,
          userAccount: userAccount,
          rejectAndRegisterAPI: rejectAndRegisterAPI,
          sendRegisterCodeAPI: sendRegisterCodeAPI);
    }
  }

  resetRegisterInfo() {
    state.registerPhone.value = "";
    state.registerCode.value = "";
    state.registerPassword.value = "";
    state.registerAgainPassword.value = "";
    state.registerInviteCode.value = "";

    state.registerIdCard.value = "";
    state.registerIdNumber.value = "";
    state.registerIdCardImage.value = [];

    state.registerIdNumberImages.value = [];
    state.registerStoreImageUrl.value = [];
    state.registerLegalUser.value = "";
    state.registerUserName.value = "";
    state.registerStoreAddr.value = "";
    state.registerAddress.value = "";
    state.registerStoreName.value = "";
    state.registerBusinessCertificateFrontUrl.value = [];
    state.registerBusinessCertificateReverseUrl.value = [];
    state.registerCertificateCode.value = "";
    state.registerSupplierName.value = "";
    state.registerBusinessImages.value = [];
    state.registerCertImages.value = [];
    state.registerDriveImages.value = [];
    state.registerCarNumber.value = "";
    state.registerDriverName.value = "";
    state.registerCarCertImages.value = [];

    registerCertificateCodeInputController.text = "";
    registerStoreNameInputController.text = "";
    registerAddressInputController.text = "";
    registerIdNumberInputController.text = "";
    registerUserNameInputController.text = "";
    registerCarNumberInputController.text = "";
    registerDriverNameInputController.text = "";
  }

  buildBusinessRegister(
      {required BuildContext context,
      required String appType,
      required String requestBaseUrl,
      required Function({String userAccount, String password}) loginAPI,
      required Function registerAPI,
      required Function loginSuccess,
      String userAccount = '',
      required Function({String userAccount, String userType})
          rejectAndRegisterAPI,
      String operationType = 'default', //操作方式，默认、补充(addToInfo)
      required Function({String mobile}) sendRegisterCodeAPI}) async {
    var info = {}.obs;
    if (operationType == 'addToInfo') {
      var map = {"worker": "2", "business": "3", "supplier": "4"};
      info.value = await rejectAndRegisterAPI(
          userAccount: userAccount, userType: showText(map[appType]));

      print("补充信息返回");
      print(info.value);
      var businessImages = showText(info.value["businessImages"]);
      state.registerBusinessImages.value = businessImages.split(",");

      var certificateCode = showText(info.value["certificateCode"]);
      state.registerCertificateCode.value = certificateCode;
      registerCertificateCodeInputController.text = certificateCode;

      var storeName = showText(info.value["storeName"]);
      state.registerStoreName.value = storeName;
      registerStoreNameInputController.text = storeName;

      var address = showText(info.value["address"]);
      state.registerAddress.value = address;
      registerAddressInputController.text = address;

      var idNumberImages = showText(info.value["idNumberImages"]);
      state.registerIdNumberImages.value = idNumberImages.split(",");

      var userName = showText(info.value["userName"]);
      state.registerUserName.value = userName;
      registerUserNameInputController.text = userName;

      var idNumber = showText(info.value["idNumber"]);
      state.registerIdNumber.value = idNumber;
      registerIdNumberInputController.text = idNumber;

      var storeImageUrl = showText(info.value["storeImageUrl"]);
      state.registerStoreImageUrl.value = storeImageUrl.split(",");

      var phone = showText(info.value["userAccount"]);
      state.registerPhone.value = phone;
      registerPhoneInputController.text = phone;

      var reason = showText(info.value["reason"]);
      state.reason.value = reason;
    }
    Get.bottomSheet(
        isScrollControlled: true,
        SizedBox(
            height: double.infinity,
            child: Obx(() => Container(
                width: double.infinity,
                height: double.infinity,
                color: Colors.white,
                child: Column(children: [
                  buildBanner(
                      context: context,
                      hasBack: true,
                      solt: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox(
                            width: double.infinity,
                            child: Row(
                              children: [
                                Visibility(
                                    visible: operationType == 'addToInfo',
                                    child: const Text(
                                      "补充",
                                      style: TextStyle(
                                          fontSize: 26,
                                          color: Colors.red,
                                          fontWeight: FontWeight.bold),
                                    )),
                                const Text(
                                  "商家",
                                  style: TextStyle(
                                      fontSize: 26,
                                      color: Colors.red,
                                      fontWeight: FontWeight.bold),
                                ),
                                const Text(
                                  "信息",
                                  style: TextStyle(
                                      fontSize: 26,
                                      fontWeight: FontWeight.bold),
                                )
                              ],
                            ),
                          ),
                          const SizedBox(
                            height: 5,
                          ),
                          Visibility(
                              visible: operationType == 'default',
                              child: const SizedBox(
                                child: Text(
                                  "请输入商家信息后填写手机号注册",
                                  style: TextStyle(
                                      fontSize: 15, color: Color(0xff666666)),
                                ),
                              )),
                          Visibility(
                              visible: operationType == 'addToInfo',
                              child: SizedBox(
                                child: Text(
                                  state.reason.value,
                                  style: const TextStyle(
                                      fontSize: 15, color: Color(0xff666666)),
                                ),
                              ))
                        ],
                      )),
                  Expanded(
                      child: SingleChildScrollView(
                          physics: const AlwaysScrollableScrollPhysics(),
                          child: Column(children: [
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(
                                    child:
                                        buildTitle(title: "营业执照/开户许可证/一般纳税人"))
                              ],
                            )),
                            buildContainer(
                                child: buildUpload(
                                    list: state.registerBusinessImages,
                                    rowCount: 3,
                                    max: 3,
                                    imageType: "BusinessLicense",
                                    onOcrContent: (orcData) {
                                      handleOrcData(
                                          imageType: "BusinessLicense",
                                          orcData: orcData);
                                    },
                                    onChange: (type, value, index) {
                                      if (type == 'add') {
                                        print("添加返回");
                                        print(value);
                                        state.registerBusinessImages.add(value);
                                      }
                                      if (type == 'del') {
                                        state.registerBusinessImages
                                            .removeAt(index);
                                      }
                                      if (type == 'change') {
                                        state.registerBusinessImages[index] =
                                            value;
                                      }
                                    })),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(
                                    child: buildTitle(title: "统一信用代码（以营业执照默认）"))
                              ],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                // FilteringTextInputFormatter.digitsOnly,
                                // LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              controller:
                                  registerCertificateCodeInputController,
                              placeholder: '请输入',
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.text,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerCertificateCode.value =
                                    value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(
                                    child:
                                        buildTitle(title: "公司/店面名称（以营业执照默认）"))
                              ],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                // FilteringTextInputFormatter.digitsOnly,
                                // LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '请输入',
                              controller: registerStoreNameInputController,
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.text,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerStoreName.value = value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(
                                    child:
                                        buildTitle(title: "公司/店面地址（以营业执照默认）"))
                              ],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                // FilteringTextInputFormatter.digitsOnly,
                                // LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '请输入',
                              controller: registerAddressInputController,
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.text,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerAddress.value = value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(child: buildTitle(title: "身份证（正反面）"))
                              ],
                            )),
                            buildContainer(
                              child: buildUpload(
                                  list: state.registerIdNumberImages,
                                  rowCount: 2,
                                  max: 2,
                                  imageType: "IdCard",
                                  onOcrContent: (orcData) {
                                    handleOrcData(
                                        imageType: "IdCard", orcData: orcData);
                                  },
                                  onChange: (type, value, index) {
                                    if (type == 'add') {
                                      print("添加返回");
                                      state.registerIdNumberImages.add(value);
                                    }
                                    if (type == 'del') {
                                      state.registerIdNumberImages
                                          .removeAt(index);
                                    }
                                    if (type == 'change') {
                                      state.registerIdNumberImages[index] =
                                          value;
                                    }
                                  }),
                            ),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(
                                    child: buildTitle(title: "法人身份证名称（以身份证默认）"))
                              ],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                // FilteringTextInputFormatter.digitsOnly,
                                // LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '请输入',
                              controller: registerUserNameInputController,
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerUserName.value = value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(
                                    child: buildTitle(title: "法人身份证号码（以身份证默认）"))
                              ],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                // FilteringTextInputFormatter.digitsOnly,
                                // LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '请输入',
                              controller: registerIdNumberInputController,
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerIdNumber.value = value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(child: buildTitle(title: "公司/店面门头照片"))
                              ],
                            )),
                            buildContainer(
                                child: buildUpload(
                                    list: state.registerStoreImageUrl,
                                    rowCount: 2,
                                    max: 2,
                                    onChange: (type, value, index) {
                                      if (type == 'add') {
                                        print("添加返回");
                                        state.registerStoreImageUrl.add(value);
                                      }
                                      if (type == 'del') {
                                        state.registerStoreImageUrl
                                            .removeAt(index);
                                      }
                                      if (type == 'change') {
                                        state.registerStoreImageUrl[index] =
                                            value;
                                      }
                                    })),
                            buildContainer(
                                child: buildButton(
                                    title: "下一步",
                                    height: 60,
                                    borderRadius: 5,
                                    onClick: () {
                                      var idNumber =
                                          state.registerIdNumber.value;
                                      var idNumberImages =
                                          state.registerIdNumberImages.value;
                                      var storeImageUrl =
                                          state.registerStoreImageUrl.value;
                                      var userName =
                                          state.registerUserName.value;
                                      var address = state.registerAddress.value;
                                      var storeName =
                                          state.registerStoreName.value;

                                      var businessImages =
                                          state.registerBusinessImages.value;
                                      var certificateCode =
                                          state.registerCertificateCode.value;

                                      // if (businessImages.isEmpty) {
                                      //   EasyLoading.showToast(
                                      //       "请上传营业执照/开户许可证/一般纳税人");
                                      //   return;
                                      // }
                                      if (certificateCode.isEmpty) {
                                        EasyLoading.showToast("请输入统一社会信用代码");
                                        return;
                                      }
                                      if (storeName.isEmpty) {
                                        EasyLoading.showToast("请输入公司/店面名称");
                                        return;
                                      }
                                      if (address.isEmpty) {
                                        EasyLoading.showToast("请输入公司/店面地址");
                                        return;
                                      }

                                      if (idNumber.isEmpty) {
                                        EasyLoading.showToast("请输入身份证");
                                        return;
                                      }
                                      // if (idNumberImages.isEmpty) {
                                      //   EasyLoading.showToast("请上传身份证照片");
                                      //   return;
                                      // }
                                      if (userName.isEmpty) {
                                        EasyLoading.showToast("请输入法人名称");
                                        return;
                                      }

                                      if (storeImageUrl.isEmpty) {
                                        EasyLoading.showToast("请上传公司/店铺图片");
                                        return;
                                      }

                                      buildBusinessRegisterNext(
                                          context: context,
                                          appType: appType,
                                          loginAPI: loginAPI,
                                          requestBaseUrl: requestBaseUrl,
                                          registerAPI: registerAPI,
                                          operationType: operationType,
                                          loginSuccess: loginSuccess,
                                          sendRegisterCodeAPI:
                                              sendRegisterCodeAPI);
                                    },
                                    colors: [
                                  const Color(0xffe53627),
                                  const Color(0xffe53627)
                                ]))
                          ])))
                ])))));
  }

  buildBusinessRegisterNext(
      {required BuildContext context,
      required String appType,
      required String requestBaseUrl,
      required Function({String userAccount, String password}) loginAPI,
      required Function registerAPI,
      required Function loginSuccess,
      String operationType = 'default', //操作方式，默认、补充(addToInfo)
      required Function({String mobile}) sendRegisterCodeAPI}) {
    //清空本页面
    if (operationType == 'default') {
      state.registerPhone.value = "";
      state.registerCode.value = "";
      state.registerPassword.value = "";
      state.registerAgainPassword.value = "";
      state.registerInviteCode.value = "";
    }

    Get.bottomSheet(
        isScrollControlled: true,
        SizedBox(
            height: double.infinity,
            child: Container(
                width: double.infinity,
                height: double.infinity,
                color: Colors.white,
                child: Column(children: [
                  buildBanner(
                      context: context,
                      hasBack: true,
                      solt: const Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox(
                            width: double.infinity,
                            child: Row(
                              children: [
                                Text(
                                  "注册",
                                  style: TextStyle(
                                      fontSize: 26,
                                      color: Colors.red,
                                      fontWeight: FontWeight.bold),
                                ),
                                Text(
                                  "账号",
                                  style: TextStyle(
                                      fontSize: 26,
                                      fontWeight: FontWeight.bold),
                                )
                              ],
                            ),
                          ),
                          SizedBox(
                            height: 5,
                          ),
                          SizedBox(
                            child: Text(
                              "请输入手机号，收取验证码并设置密码",
                              style: TextStyle(
                                  fontSize: 15, color: Color(0xff666666)),
                            ),
                          )
                        ],
                      )),
                  Expanded(
                      child: SingleChildScrollView(
                          physics: const AlwaysScrollableScrollPhysics(),
                          child: Column(children: [
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [buildTitle(title: "手机号")],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                FilteringTextInputFormatter.digitsOnly,
                                LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              controller: registerPhoneInputController,
                              placeholder: '请输入',
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerPhone.value = value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [buildTitle(title: "验证码")],
                            )),
                            buildContainer(
                              child: Stack(
                                alignment: Alignment.topRight,
                                children: [
                                  CupertinoTextFormFieldRow(
                                    padding: const EdgeInsets.only(
                                        left: 0, right: 0),
                                    style: const TextStyle(fontSize: 18),
                                    // controller: codeInputController,
                                    // focusNode: controller.codeFocusNode,
                                    inputFormatters: [
                                      FilteringTextInputFormatter.digitsOnly,
                                      LengthLimitingTextInputFormatter(
                                          6), //限制长度
                                    ],
                                    // prefix: const Center(child: Icon(Icons.message)),
                                    placeholder: '验证码',
                                    placeholderStyle: TextStyle(
                                        color: CupertinoColors
                                            .darkBackgroundGray
                                            .withOpacity(.7)),
                                    keyboardType: TextInputType.emailAddress,
                                    keyboardAppearance: Brightness.dark,
                                    onChanged: (value) => {
                                      state.registerCode.value =
                                          value.toString()
                                    },
                                  ),
                                  Container(
                                    padding: const EdgeInsets.only(right: 30),
                                    child: OutlinedButton(
                                        onPressed: () => {
                                              getRegisterCode(
                                                  sendRegisterCodeAPI:
                                                      sendRegisterCodeAPI)
                                            },
                                        style: ButtonStyle(
                                          side: MaterialStateProperty.all(
                                              const BorderSide(
                                                  width: 0.0,
                                                  color: Colors.transparent)),
                                          shape: MaterialStateProperty.all(
                                              RoundedRectangleBorder(
                                                  borderRadius:
                                                      BorderRadius.circular(
                                                          20))),
                                          textStyle: MaterialStateProperty.all(
                                              const TextStyle(fontSize: 16)),
                                        ),
                                        child: Obx(() => Text(
                                              state.registerWaitTitle.value,
                                              style: const TextStyle(
                                                color: Color(0xffE69C24),
                                              ),
                                            ))),
                                  )
                                ],
                              ),
                            ),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [buildTitle(title: "密码")],
                            )),
                            buildContainer(
                              child: CupertinoTextFormFieldRow(
                                padding:
                                    const EdgeInsets.only(left: 0, right: 0),
                                style: const TextStyle(fontSize: 18),
                                // controller: passwordInputController,
                                // focusNode: controller.passwordFocusNode,
                                obscureText: true,
                                // prefix: const Center(child: Icon(Icons.message)),
                                placeholder: '请输入',
                                placeholderStyle: TextStyle(
                                    color: CupertinoColors.darkBackgroundGray
                                        .withOpacity(.7)),
                                keyboardType: TextInputType.emailAddress,
                                keyboardAppearance: Brightness.dark,
                                onChanged: (value) => {
                                  state.registerPassword.value =
                                      value.toString()
                                },
                              ),
                            ),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [buildTitle(title: "确认密码")],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              // controller: passwordInputController,
                              // focusNode: controller.passwordFocusNode,
                              obscureText: true,
                              // prefix: const Center(child: Icon(Icons.message)),
                              placeholder: '请输入',
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerAgainPassword.value =
                                    value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [buildTitle(title: "邀请码（选填）")],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                FilteringTextInputFormatter.digitsOnly,
                                LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '请输入',
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerInviteCode.value =
                                    value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              children: [
                                Expanded(
                                    child: Padding(
                                  padding: const EdgeInsets.all(5),
                                  child: buildButton(
                                      title: "上一步",
                                      height: 60,
                                      borderRadius: 5,
                                      fontColor: const Color(0xff4b4b4b),
                                      onClick: () {
                                        Get.back();
                                      },
                                      colors: [
                                        const Color(0xfff7f7f7),
                                        const Color(0xfff7f7f7)
                                      ]),
                                )),
                                Expanded(
                                    child: Padding(
                                        padding: const EdgeInsets.all(5),
                                        child: buildButton(
                                            title: "立即注册",
                                            height: 60,
                                            borderRadius: 5,
                                            onClick: () {
                                              //检查同意按钮
                                              var isRead = state.isRead.value;
                                              if (!isRead) {
                                                EasyLoading.showToast(
                                                    "请勾选同意按钮");
                                                return;
                                              }
                                              handleRegister(
                                                  appType: appType,
                                                  loginAPI: loginAPI,
                                                  loginSuccess: loginSuccess,
                                                  registerAPI: registerAPI);
                                            },
                                            colors: [
                                              const Color(0xffe53627),
                                              const Color(0xffe53627)
                                            ])))
                              ],
                            )),
                            buildRadio(
                              appType: appType,
                              requestBaseUrl: requestBaseUrl,
                            ),
                            SizedBox(
                              height: 30,
                            )
                          ])))
                ]))));
  }

  buildWorkerRegister(
      {required BuildContext context,
      required String appType,
      required String requestBaseUrl,
      required Function({String userAccount, String password}) loginAPI,
      required Function registerAPI,
      required Function loginSuccess,
      String userAccount = '',
      required Function({String userAccount, String userType})
          rejectAndRegisterAPI,
      String operationType = 'default', //操作方式，默认、补充(addToInfo)
      required Function({String mobile}) sendRegisterCodeAPI}) async {
    var info = {}.obs;
    if (operationType == 'addToInfo') {
      var map = {"worker": "2", "business": "3", "supplier": "4"};
      info.value = await rejectAndRegisterAPI(
          userAccount: userAccount, userType: showText(map[appType]));
      print("补充信息返回");
      print(info.value);

      var idNumberImages = showText(info.value["idNumberImages"]);
      state.registerIdNumberImages.value = idNumberImages.split(",");

      var userName = showText(info.value["userName"]);
      state.registerUserName.value = userName;
      registerUserNameInputController.text = userName;

      var idNumber = showText(info.value["idNumber"]);
      state.registerIdNumber.value = idNumber;
      registerIdNumberInputController.text = idNumber;

      var driveImages = showText(info.value["driveImages"]);
      state.registerDriveImages.value = driveImages.split(",");

      var carNumber = showText(info.value["carNumber"]);
      state.registerCarNumber.value = carNumber;
      registerCarNumberInputController.text = carNumber;

      var carCertImages = showText(info.value["carCertImages"]);
      state.registerCarCertImages.value = carCertImages.split(",");

      var driverName = showText(info.value["driverName"]);
      state.registerDriverName.value = driverName;
      registerDriverNameInputController.text = driverName;

      var phone = showText(info.value["userAccount"]);
      state.registerPhone.value = phone;
      registerPhoneInputController.text = phone;

      var reason = showText(info.value["reason"]);
      state.reason.value = reason;
    }
    Get.bottomSheet(
        isScrollControlled: true,
        SizedBox(
            height: double.infinity,
            child: Obx(() => Container(
                width: double.infinity,
                height: double.infinity,
                color: Colors.white,
                child: Column(children: [
                  buildBanner(
                      context: context,
                      hasBack: true,
                      solt: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox(
                            width: double.infinity,
                            child: Row(
                              children: [
                                Visibility(
                                    visible: operationType == 'addToInfo',
                                    child: const Text(
                                      "补充",
                                      style: TextStyle(
                                          fontSize: 26,
                                          color: Colors.red,
                                          fontWeight: FontWeight.bold),
                                    )),
                                const Text(
                                  "师傅",
                                  style: TextStyle(
                                      fontSize: 26,
                                      color: Colors.red,
                                      fontWeight: FontWeight.bold),
                                ),
                                const Text(
                                  "信息",
                                  style: TextStyle(
                                      fontSize: 26,
                                      fontWeight: FontWeight.bold),
                                )
                              ],
                            ),
                          ),
                          const SizedBox(
                            height: 5,
                          ),
                          Visibility(
                              visible: operationType == 'default',
                              child: const SizedBox(
                                child: Text(
                                  "请输入师傅信息后填写手机号注册",
                                  style: TextStyle(
                                      fontSize: 15, color: Color(0xff666666)),
                                ),
                              )),
                          Visibility(
                              visible: operationType == 'addToInfo',
                              child: SizedBox(
                                child: Text(
                                  state.reason.value,
                                  style: const TextStyle(
                                      fontSize: 15, color: Color(0xff666666)),
                                ),
                              ))
                        ],
                      )),
                  Expanded(
                      child: SingleChildScrollView(
                          physics: const AlwaysScrollableScrollPhysics(),
                          child: Column(children: [
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(child: buildTitle(title: "身份证（正反面）"))
                              ],
                            )),
                            buildContainer(
                                child: buildUpload(
                                    list: state.registerIdNumberImages,
                                    rowCount: 2,
                                    max: 2,
                                    imageType: "IdCard",
                                    onOcrContent: (orcData) {
                                      handleOrcData(
                                          imageType: "IdCard",
                                          orcData: orcData);
                                    },
                                    onChange: (type, value, index) {
                                      if (type == 'add') {
                                        print("添加返回");
                                        state.registerIdNumberImages.add(value);
                                      }
                                      if (type == 'del') {
                                        state.registerIdNumberImages
                                            .removeAt(index);
                                      }
                                      if (type == 'change') {
                                        state.registerIdNumberImages[index] =
                                            value;
                                      }
                                    })),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(child: buildTitle(title: "姓名（以身份证默认）"))
                              ],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                // FilteringTextInputFormatter.digitsOnly,
                                // LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              controller: registerUserNameInputController,
                              placeholder: '请输入',
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.text,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerUserName.value = value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(
                                    child: buildTitle(title: "身份证号码（以身份证默认）"))
                              ],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                // FilteringTextInputFormatter.digitsOnly,
                                // LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '请输入',
                              controller: registerIdNumberInputController,
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerIdNumber.value = value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(
                                    child: buildTitle(title: "行驶证/流动服务车照片"))
                              ],
                            )),
                            buildContainer(
                                child: buildUpload(
                                    list: state.registerDriveImages,
                                    rowCount: 3,
                                    max: 3,
                                    imageType: "VehicleLicense",
                                    onOcrContent: (orcData) {
                                      print("识别行驶证======》");
                                      print(orcData);

                                      handleOrcData(
                                          imageType: "VehicleLicense",
                                          orcData: orcData);
                                    },
                                    onChange: (type, value, index) {
                                      if (type == 'add') {
                                        print("添加返回");
                                        state.registerDriveImages.add(value);
                                      }
                                      if (type == 'del') {
                                        state.registerDriveImages
                                            .removeAt(index);
                                      }
                                      if (type == 'change') {
                                        state.registerDriveImages[index] =
                                            value;
                                      }
                                    })),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(child: buildTitle(title: "服务车牌"))
                              ],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                // FilteringTextInputFormatter.digitsOnly,
                                // LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '请输入',
                              controller: registerCarNumberInputController,
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerCarNumber.value = value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(child: buildTitle(title: "驾驶证"))
                              ],
                            )),
                            buildContainer(
                                child: buildUpload(
                                    list: state.registerCarCertImages,
                                    rowCount: 3,
                                    max: 3,
                                    imageType: "DrivingLicense",
                                    onOcrContent: (orcData) {
                                      print("识别驾驶证======》");
                                      print(orcData);

                                      handleOrcData(
                                          imageType: "DrivingLicense",
                                          orcData: orcData);
                                    },
                                    onChange: (type, value, index) {
                                      if (type == 'add') {
                                        print("添加返回");
                                        state.registerCarCertImages.add(value);
                                      }
                                      if (type == 'del') {
                                        state.registerCarCertImages
                                            .removeAt(index);
                                      }
                                      if (type == 'change') {
                                        state.registerCarCertImages[index] =
                                            value;
                                      }
                                    })),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(child: buildTitle(title: "驾驶证姓名"))
                              ],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                // FilteringTextInputFormatter.digitsOnly,
                                // LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '请输入',
                              controller: registerDriverNameInputController,
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.text,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerDriverName.value =
                                    value.toString()
                              },
                            )),
                            buildContainer(
                                child: buildButton(
                                    title: "下一步",
                                    height: 60,
                                    borderRadius: 5,
                                    onClick: () {
                                      //校验
                                      var idNumber =
                                          state.registerIdNumber.value;
                                      var idNumberImages =
                                          state.registerIdNumberImages.value;
                                      var userName =
                                          state.registerUserName.value;
                                      var driveImages =
                                          state.registerDriveImages.value;
                                      var carNumber =
                                          state.registerCarNumber.value;
                                      var driverName =
                                          state.registerDriverName.value;
                                      var carCertImages =
                                          state.registerCarCertImages.value;
                                      // if (idNumberImages.isEmpty) {
                                      //   EasyLoading.showToast("请上传身份改正反面");
                                      //   return;
                                      // }
                                      if (userName.isEmpty) {
                                        EasyLoading.showToast("请输入身份证姓名");
                                        return;
                                      }
                                      if (idNumber.isEmpty) {
                                        EasyLoading.showToast("请输入身份证号码");
                                        return;
                                      }

                                      if (carCertImages.isEmpty) {
                                        EasyLoading.showToast("请上传驾驶证");
                                        return;
                                      }

                                      if (driverName.isEmpty) {
                                        EasyLoading.showToast("请输入驾驶证姓名");
                                        return;
                                      }

                                      if (driveImages.isEmpty) {
                                        EasyLoading.showToast("请上传行驶证/流动服务车照片");
                                        return;
                                      }

                                      if (carNumber.isEmpty) {
                                        EasyLoading.showToast("请输入服务车车牌");
                                        return;
                                      }

                                      buildWorkerRegisterNext(
                                          context: context,
                                          appType: appType,
                                          loginAPI: loginAPI,
                                          requestBaseUrl: requestBaseUrl,
                                          operationType: operationType,
                                          registerAPI: registerAPI,
                                          loginSuccess: loginSuccess,
                                          sendRegisterCodeAPI:
                                              sendRegisterCodeAPI);
                                    },
                                    colors: [
                                  const Color(0xffe53627),
                                  const Color(0xffe53627)
                                ]))
                          ])))
                ])))));
  }

  buildWorkerRegisterNext(
      {required BuildContext context,
      required String appType,
      required String requestBaseUrl,
      required Function({String userAccount, String password}) loginAPI,
      required Function registerAPI,
      required Function loginSuccess,
      String operationType = 'default', //操作方式，默认、补充(addToInfo)
      required Function({String mobile}) sendRegisterCodeAPI}) {
    //清空本页面
    if (operationType == 'default') {
      state.registerPhone.value = "";
      state.registerCode.value = "";
      state.registerPassword.value = "";
      state.registerAgainPassword.value = "";
      state.registerInviteCode.value = "";
    }

    Get.bottomSheet(
        isScrollControlled: true,
        SizedBox(
            height: double.infinity,
            child: Container(
                width: double.infinity,
                height: double.infinity,
                color: Colors.white,
                child: Column(children: [
                  buildBanner(
                      context: context,
                      hasBack: true,
                      solt: const Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox(
                            width: double.infinity,
                            child: Row(
                              children: [
                                Text(
                                  "注册",
                                  style: TextStyle(
                                      fontSize: 26,
                                      color: Colors.red,
                                      fontWeight: FontWeight.bold),
                                ),
                                Text(
                                  "账号",
                                  style: TextStyle(
                                      fontSize: 26,
                                      fontWeight: FontWeight.bold),
                                )
                              ],
                            ),
                          ),
                          SizedBox(
                            height: 5,
                          ),
                          SizedBox(
                            child: Text(
                              "请输入手机号，收取验证码并设置密码",
                              style: TextStyle(
                                  fontSize: 15, color: Color(0xff666666)),
                            ),
                          )
                        ],
                      )),
                  Expanded(
                      child: SingleChildScrollView(
                          physics: const AlwaysScrollableScrollPhysics(),
                          child: Column(children: [
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [buildTitle(title: "手机号")],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              controller: registerPhoneInputController,
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                FilteringTextInputFormatter.digitsOnly,
                                LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '请输入',
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerPhone.value = value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [buildTitle(title: "验证码")],
                            )),
                            buildContainer(
                                child: Stack(
                              alignment: Alignment.topRight,
                              children: [
                                CupertinoTextFormFieldRow(
                                  padding:
                                      const EdgeInsets.only(left: 0, right: 0),
                                  style: const TextStyle(fontSize: 18),
                                  // controller: codeInputController,
                                  // focusNode: controller.codeFocusNode,
                                  inputFormatters: [
                                    FilteringTextInputFormatter.digitsOnly,
                                    LengthLimitingTextInputFormatter(6), //限制长度
                                  ],
                                  // prefix: const Center(child: Icon(Icons.message)),
                                  placeholder: '验证码',
                                  placeholderStyle: TextStyle(
                                      color: CupertinoColors.darkBackgroundGray
                                          .withOpacity(.7)),
                                  keyboardType: TextInputType.emailAddress,
                                  keyboardAppearance: Brightness.dark,
                                  onChanged: (value) => {
                                    state.registerCode.value = value.toString()
                                  },
                                ),
                                Container(
                                  padding: const EdgeInsets.only(right: 30),
                                  child: OutlinedButton(
                                      onPressed: () => {
                                            getRegisterCode(
                                                sendRegisterCodeAPI:
                                                    sendRegisterCodeAPI)
                                          },
                                      style: ButtonStyle(
                                        side: MaterialStateProperty.all(
                                            const BorderSide(
                                                width: 0.0,
                                                color: Colors.transparent)),
                                        shape: MaterialStateProperty.all(
                                            RoundedRectangleBorder(
                                                borderRadius:
                                                    BorderRadius.circular(20))),
                                        textStyle: MaterialStateProperty.all(
                                            const TextStyle(fontSize: 16)),
                                      ),
                                      child: Obx(() => Text(
                                            state.registerWaitTitle.value,
                                            style: const TextStyle(
                                              color: Color(0xffE69C24),
                                            ),
                                          ))),
                                )
                              ],
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [buildTitle(title: "密码")],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              // controller: passwordInputController,
                              // focusNode: controller.passwordFocusNode,
                              obscureText: true,
                              // prefix: const Center(child: Icon(Icons.message)),
                              placeholder: '*密码',
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerPassword.value = value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [buildTitle(title: "确认密码")],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              // controller: passwordInputController,
                              // focusNode: controller.passwordFocusNode,
                              obscureText: true,
                              // prefix: const Center(child: Icon(Icons.message)),
                              placeholder: '*确认密码',
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerAgainPassword.value =
                                    value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [buildTitle(title: "邀请码")],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                FilteringTextInputFormatter.digitsOnly,
                                LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '邀请码（选填）',
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerInviteCode.value =
                                    value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              children: [
                                Expanded(
                                    child: Padding(
                                  padding: const EdgeInsets.all(5),
                                  child: buildButton(
                                      title: "上一步",
                                      height: 60,
                                      borderRadius: 5,
                                      fontColor: const Color(0xff4b4b4b),
                                      onClick: () {
                                        Get.back();
                                      },
                                      colors: [
                                        const Color(0xfff7f7f7),
                                        const Color(0xfff7f7f7)
                                      ]),
                                )),
                                Expanded(
                                    child: Padding(
                                        padding: const EdgeInsets.all(5),
                                        child: buildButton(
                                            title: "立即注册",
                                            height: 60,
                                            borderRadius: 5,
                                            onClick: () {
                                              //检查同意按钮
                                              var isRead = state.isRead.value;
                                              if (!isRead) {
                                                EasyLoading.showToast(
                                                    "请勾选同意按钮");
                                                return;
                                              }
                                              handleRegister(
                                                  appType: appType,
                                                  loginAPI: loginAPI,
                                                  loginSuccess: loginSuccess,
                                                  registerAPI: registerAPI);
                                            },
                                            colors: [
                                              const Color(0xffe53627),
                                              const Color(0xffe53627)
                                            ])))
                              ],
                            )),
                            buildRadio(
                              appType: appType,
                              requestBaseUrl: requestBaseUrl,
                            ),
                            SizedBox(
                              height: 30,
                            )
                          ])))
                ]))));
  }

  buildSupplierRegister(
      {required BuildContext context,
      required String appType,
      required String requestBaseUrl,
      required Function({String userAccount, String password}) loginAPI,
      required Function registerAPI,
      required Function loginSuccess,
      String userAccount = '',
      required Function({String userAccount, String userType})
          rejectAndRegisterAPI,
      String operationType = 'default', //操作方式，默认、补充(addToInfo)
      required Function({String mobile}) sendRegisterCodeAPI}) async {
    var info = {}.obs;
    if (operationType == 'addToInfo') {
      var map = {"worker": "2", "business": "3", "supplier": "4"};
      info.value = await rejectAndRegisterAPI(
          userAccount: userAccount, userType: showText(map[appType]));
      print("补充信息返回");
      print(info.value);

      var businessImages = showText(info.value["businessImages"]);
      state.registerBusinessImages.value = businessImages.split(",");

      var certificateCode = showText(info.value["certificateCode"]);
      state.registerCertificateCode.value = certificateCode;
      registerCertificateCodeInputController.text = certificateCode;

      var supplierName = showText(info.value["supplierName"]);
      state.registerSupplierName.value = supplierName;
      registerStoreNameInputController.text = supplierName;

      var address = showText(info.value["address"]);
      state.registerAddress.value = address;
      registerAddressInputController.text = address;

      var idNumberImages = showText(info.value["idNumberImages"]);
      state.registerIdNumberImages.value = idNumberImages.split(",");

      var userName = showText(info.value["userName"]);
      state.registerUserName.value = userName;
      registerUserNameInputController.text = userName;

      var idNumber = showText(info.value["idNumber"]);
      state.registerIdNumber.value = idNumber;
      registerIdNumberInputController.text = idNumber;

      var certImages = showText(info.value["certImages"]);
      state.registerCertImages.value = certImages.split(",");

      var phone = showText(info.value["userAccount"]);
      state.registerPhone.value = phone;
      registerPhoneInputController.text = phone;

      var reason = showText(info.value["reason"]);
      state.reason.value = reason;
    }

    Get.bottomSheet(
        isScrollControlled: true,
        SizedBox(
            height: double.infinity,
            child: Obx(() => Container(
                width: double.infinity,
                height: double.infinity,
                color: Colors.white,
                child: Column(children: [
                  buildBanner(
                      context: context,
                      hasBack: true,
                      solt: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox(
                            width: double.infinity,
                            child: Row(
                              children: [
                                Visibility(
                                    visible: operationType == 'addToInfo',
                                    child: const Text(
                                      "补充",
                                      style: TextStyle(
                                          fontSize: 26,
                                          color: Colors.red,
                                          fontWeight: FontWeight.bold),
                                    )),
                                const Text(
                                  "供应商",
                                  style: TextStyle(
                                      fontSize: 26,
                                      color: Colors.red,
                                      fontWeight: FontWeight.bold),
                                ),
                                const Text(
                                  "信息",
                                  style: TextStyle(
                                      fontSize: 26,
                                      fontWeight: FontWeight.bold),
                                )
                              ],
                            ),
                          ),
                          const SizedBox(
                            height: 5,
                          ),
                          Visibility(
                              visible: operationType == 'default',
                              child: const SizedBox(
                                child: Text(
                                  "请输入供应商信息后填写手机号注册",
                                  style: TextStyle(
                                      fontSize: 15, color: Color(0xff666666)),
                                ),
                              )),
                          Visibility(
                              visible: operationType == 'addToInfo',
                              child: SizedBox(
                                child: Text(
                                  state.reason.value,
                                  style: const TextStyle(
                                      fontSize: 15, color: Color(0xff666666)),
                                ),
                              ))
                        ],
                      )),
                  Expanded(
                      child: SingleChildScrollView(
                          physics: const AlwaysScrollableScrollPhysics(),
                          child: Column(children: [
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(
                                    child:
                                        buildTitle(title: "营业执照照片/开户许可证/一般纳税人"))
                              ],
                            )),
                            buildContainer(
                                child: buildUpload(
                                    list: state.registerBusinessImages,
                                    rowCount: 3,
                                    max: 3,
                                    imageType: "BusinessLicense",
                                    onOcrContent: (orcData) {
                                      handleOrcData(
                                          imageType: "BusinessLicense",
                                          orcData: orcData);
                                    },
                                    onChange: (type, value, index) {
                                      if (type == 'add') {
                                        state.registerBusinessImages.add(value);
                                      }
                                      if (type == 'del') {
                                        state.registerBusinessImages
                                            .removeAt(index);
                                      }
                                      if (type == 'change') {
                                        state.registerBusinessImages[index] =
                                            value;
                                      }
                                    })),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.start,
                              children: [
                                buildTitle(title: "统一信用代码"),
                                const Expanded(
                                    child: Text(
                                  "(以营业执照默认)",
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(fontSize: 16),
                                ))
                              ],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                // FilteringTextInputFormatter.digitsOnly,
                                // LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '请输入',
                              controller:
                                  registerCertificateCodeInputController,
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerCertificateCode.value =
                                    value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [buildTitle(title: "供应商名称")],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                // FilteringTextInputFormatter.digitsOnly,
                                // LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '请输入',
                              controller: registerStoreNameInputController,
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.text,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerSupplierName.value =
                                    value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [buildTitle(title: "供应商地址")],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                // FilteringTextInputFormatter.digitsOnly,
                                // LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '请输入',
                              controller: registerAddressInputController,
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.text,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerAddress.value = value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.start,
                              children: [
                                buildTitle(title: "身份证"),
                                const Expanded(
                                    child: Text(
                                  "(正反面)",
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(fontSize: 16),
                                ))
                              ],
                            )),
                            buildContainer(
                                child: buildUpload(
                                    list: state.registerIdNumberImages,
                                    rowCount: 2,
                                    max: 2,
                                    imageType: "IdCard",
                                    onOcrContent: (orcData) {
                                      handleOrcData(
                                          imageType: "IdCard",
                                          orcData: orcData);
                                    },
                                    onChange: (type, value, index) {
                                      if (type == 'add') {
                                        print("添加返回");
                                        state.registerIdNumberImages.add(value);
                                      }
                                      if (type == 'del') {
                                        state.registerIdNumberImages
                                            .removeAt(index);
                                      }
                                      if (type == 'change') {
                                        state.registerIdNumberImages[index] =
                                            value;
                                      }
                                    })),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [buildTitle(title: "法人名称")],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                // FilteringTextInputFormatter.digitsOnly,
                                // LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '请输入',
                              controller: registerUserNameInputController,
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.text,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerUserName.value = value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.start,
                              children: [
                                buildTitle(title: "法人身份证号码"),
                                const Expanded(
                                    child: Text(
                                  "(以身份证默认)",
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(fontSize: 16),
                                ))
                              ],
                            )),
                            buildContainer(
                                child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                // FilteringTextInputFormatter.digitsOnly,
                                // LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '请输入',
                              controller: registerIdNumberInputController,
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerIdNumber.value = value.toString()
                              },
                            )),
                            buildContainer(
                                child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [buildTitle(title: "品牌证书/代理证明")],
                            )),
                            buildContainer(
                                child: buildUpload(
                                    list: state.registerCertImages,
                                    rowCount: 2,
                                    max: 2,
                                    onChange: (type, value, index) {
                                      if (type == 'add') {
                                        print("添加返回");
                                        state.registerCertImages.add(value);
                                      }
                                      if (type == 'del') {
                                        state.registerCertImages
                                            .removeAt(index);
                                      }
                                      if (type == 'change') {
                                        state.registerCertImages[index] = value;
                                      }
                                    })),
                            buildContainer(
                                child: buildButton(
                                    title: "下一步",
                                    height: 60,
                                    borderRadius: 5,
                                    onClick: () {
                                      //校验数据
                                      var businessImages =
                                          state.registerBusinessImages.value;
                                      var idNumber =
                                          state.registerIdNumber.value;
                                      var idNumberImages =
                                          state.registerIdNumberImages.value;
                                      var address = state.registerAddress.value;
                                      // var storeName = state.registerStoreName.value;
                                      var supplierName =
                                          state.registerSupplierName.value;
                                      var userName =
                                          state.registerUserName.value;
                                      var certImages =
                                          state.registerCertImages.value;
                                      // if (businessImages.isEmpty) {
                                      //   EasyLoading.showToast(
                                      //       "请上传营业执照/开户许可证/一般纳税人");
                                      //   return;
                                      // }
                                      if (idNumber.isEmpty) {
                                        EasyLoading.showToast("请输入身份证");
                                        return;
                                      }

                                      if (address.isEmpty) {
                                        EasyLoading.showToast("请输入公司/店面地址");
                                        return;
                                      }
                                      if (certImages.isEmpty) {
                                        EasyLoading.showToast("请上传品牌证书/代理证明");
                                        return;
                                      }
                                      // if (idNumberImages.isEmpty) {
                                      //   EasyLoading.showToast("请上传身份证照片");
                                      //   return;
                                      // }
                                      if (userName.isEmpty) {
                                        EasyLoading.showToast("请输入法人名称");
                                        return;
                                      }
                                      if (supplierName.isEmpty) {
                                        EasyLoading.showToast("请输入供应商名称");
                                        return;
                                      }
                                      buildSupplierRegisterNext(
                                          context: context,
                                          appType: appType,
                                          requestBaseUrl: requestBaseUrl,
                                          loginAPI: loginAPI,
                                          registerAPI: registerAPI,
                                          operationType: operationType,
                                          loginSuccess: loginSuccess,
                                          sendRegisterCodeAPI:
                                              sendRegisterCodeAPI);
                                      // handleRegister(
                                      //     appType: appType,
                                      //     loginAPI: loginAPI,
                                      //     loginSuccess: loginSuccess,
                                      //     registerAPI: registerAPI);
                                    },
                                    colors: [
                                  const Color(0xffe53627),
                                  const Color(0xffe53627)
                                ]))
                          ])))
                ])))));
  }

  buildSupplierRegisterNext(
      {required BuildContext context,
      required String appType,
      required String requestBaseUrl,
      required Function({String userAccount, String password}) loginAPI,
      required Function registerAPI,
      required Function loginSuccess,
      String operationType = 'default', //操作方式，默认、补充(addToInfo)
      required Function({String mobile}) sendRegisterCodeAPI}) {
    //清空本页面
    if (operationType == 'default') {
      state.registerPhone.value = "";
      state.registerCode.value = "";
      state.registerPassword.value = "";
      state.registerAgainPassword.value = "";
      state.registerInviteCode.value = "";
    }

    registerPhoneInputController.text = state.registerPhone.value;
    Get.bottomSheet(
        isScrollControlled: true,
        SizedBox(
            height: double.infinity,
            child: Container(
                width: double.infinity,
                height: double.infinity,
                color: Colors.white,
                child: Column(
                  children: [
                    buildBanner(
                        context: context,
                        hasBack: true,
                        solt: const Column(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            SizedBox(
                              width: double.infinity,
                              child: Row(
                                children: [
                                  Text(
                                    "注册",
                                    style: TextStyle(
                                        fontSize: 26,
                                        color: Colors.red,
                                        fontWeight: FontWeight.bold),
                                  ),
                                  Text(
                                    "账号",
                                    style: TextStyle(
                                        fontSize: 26,
                                        fontWeight: FontWeight.bold),
                                  )
                                ],
                              ),
                            ),
                            SizedBox(
                              height: 5,
                            ),
                            SizedBox(
                              child: Text(
                                "请输入手机号，收取验证码并设置密码",
                                style: TextStyle(
                                    fontSize: 15, color: Color(0xff666666)),
                              ),
                            )
                          ],
                        )),
                    Expanded(
                        child: SingleChildScrollView(
                      physics: const AlwaysScrollableScrollPhysics(),
                      child: Column(
                        children: [
                          buildContainer(
                              child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [buildTitle(title: "手机号")],
                          )),
                          buildContainer(
                              child: CupertinoTextFormFieldRow(
                            padding: const EdgeInsets.only(left: 0, right: 0),
                            style: const TextStyle(fontSize: 18),
                            controller: registerPhoneInputController,
                            inputFormatters: [
                              FilteringTextInputFormatter.digitsOnly,
                              LengthLimitingTextInputFormatter(11), //限制长度
                            ],
                            placeholder: '请输入手机号',
                            placeholderStyle: TextStyle(
                                color: CupertinoColors.darkBackgroundGray
                                    .withOpacity(.7)),
                            keyboardType: TextInputType.emailAddress,
                            keyboardAppearance: Brightness.dark,
                            onChanged: (value) {
                              state.registerPhone.value = value.toString();
                            },
                          )),
                          buildContainer(
                              child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [buildTitle(title: "验证码")],
                          )),
                          buildContainer(
                            child: Stack(
                              alignment: Alignment.topRight,
                              children: [
                                CupertinoTextFormFieldRow(
                                  padding:
                                      const EdgeInsets.only(left: 0, right: 0),
                                  style: const TextStyle(fontSize: 18),
                                  inputFormatters: [
                                    FilteringTextInputFormatter.digitsOnly,
                                    LengthLimitingTextInputFormatter(6), //限制长度
                                  ],
                                  placeholder: '验证码',
                                  placeholderStyle: TextStyle(
                                      color: CupertinoColors.darkBackgroundGray
                                          .withOpacity(.7)),
                                  keyboardType: TextInputType.emailAddress,
                                  keyboardAppearance: Brightness.dark,
                                  onChanged: (value) => {
                                    state.registerCode.value = value.toString()
                                  },
                                ),
                                Container(
                                  padding: const EdgeInsets.only(right: 30),
                                  child: OutlinedButton(
                                      onPressed: () => {
                                            getRegisterCode(
                                                sendRegisterCodeAPI:
                                                    sendRegisterCodeAPI)
                                          },
                                      style: ButtonStyle(
                                        side: MaterialStateProperty.all(
                                            const BorderSide(
                                                width: 0.0,
                                                color: Colors.transparent)),
                                        shape: MaterialStateProperty.all(
                                            RoundedRectangleBorder(
                                                borderRadius:
                                                    BorderRadius.circular(20))),
                                        textStyle: MaterialStateProperty.all(
                                            const TextStyle(fontSize: 18)),
                                      ),
                                      child: Obx(() => Text(
                                            state.registerWaitTitle.value,
                                            style: const TextStyle(
                                              color: Colors.red,
                                            ),
                                          ))),
                                )
                              ],
                            ),
                          ),
                          buildContainer(
                              child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [buildTitle(title: "密码")],
                          )),
                          buildContainer(
                              child: CupertinoTextFormFieldRow(
                            padding: const EdgeInsets.only(left: 0, right: 0),
                            style: const TextStyle(fontSize: 18),
                            obscureText: true,
                            placeholder: '*密码',
                            placeholderStyle: TextStyle(
                                color: CupertinoColors.darkBackgroundGray
                                    .withOpacity(.7)),
                            keyboardType: TextInputType.emailAddress,
                            keyboardAppearance: Brightness.dark,
                            onChanged: (value) => {
                              state.registerPassword.value = value.toString()
                            },
                          )),
                          buildContainer(
                              child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [buildTitle(title: "确认密码")],
                          )),
                          buildContainer(
                              child: CupertinoTextFormFieldRow(
                            padding: const EdgeInsets.only(left: 0, right: 0),
                            style: const TextStyle(fontSize: 18),
                            obscureText: true,
                            placeholder: '*确认密码',
                            placeholderStyle: TextStyle(
                                color: CupertinoColors.darkBackgroundGray
                                    .withOpacity(.7)),
                            keyboardType: TextInputType.emailAddress,
                            keyboardAppearance: Brightness.dark,
                            onChanged: (value) => {
                              state.registerAgainPassword.value =
                                  value.toString()
                            },
                          )),
                          buildContainer(
                              child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [buildTitle(title: "邀请码")],
                          )),
                          buildContainer(
                            child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                FilteringTextInputFormatter.digitsOnly,
                                LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '邀请码（选填）',
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerInviteCode.value =
                                    value.toString()
                              },
                            ),
                          ),
                          buildContainer(
                              child: Row(
                            children: [
                              Expanded(
                                  child: Padding(
                                padding: const EdgeInsets.all(5),
                                child: buildButton(
                                    title: "上一步",
                                    height: 60,
                                    borderRadius: 5,
                                    fontColor: const Color(0xff4b4b4b),
                                    onClick: () {
                                      Get.back();
                                    },
                                    colors: [
                                      const Color(0xfff7f7f7),
                                      const Color(0xfff7f7f7)
                                    ]),
                              )),
                              Expanded(
                                  child: Padding(
                                      padding: const EdgeInsets.all(5),
                                      child: buildButton(
                                          title: "立即注册",
                                          height: 60,
                                          borderRadius: 5,
                                          onClick: () {
                                            //检查同意按钮
                                            var isRead = state.isRead.value;
                                            if (!isRead) {
                                              EasyLoading.showToast("请勾选同意按钮");
                                              return;
                                            }
                                            handleRegister(
                                                appType: appType,
                                                loginAPI: loginAPI,
                                                loginSuccess: loginSuccess,
                                                registerAPI: registerAPI);
                                          },
                                          colors: [
                                            const Color(0xffe53627),
                                            const Color(0xffe53627)
                                          ])))
                            ],
                          )),
                          buildRadio(
                            appType: appType,
                            requestBaseUrl: requestBaseUrl,
                          ),
                          SizedBox(
                            height: 30,
                          )
                        ],
                      ),
                    )),
                  ],
                ))));
  }

  buildUserRegister(
      {required BuildContext context,
      required String appType,
      required String requestBaseUrl,
      required Function({String userAccount, String password}) loginAPI,
      required Function registerAPI,
      required Function loginSuccess,
      required Function({String mobile}) sendRegisterCodeAPI}) {
    Get.bottomSheet(
        isScrollControlled: true,
        SizedBox(
            height: double.infinity,
            child: Container(
                width: double.infinity,
                height: double.infinity,
                color: Colors.white,
                child: Column(
                  children: [
                    buildBanner(
                        context: context,
                        hasBack: true,
                        solt: const Column(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            SizedBox(
                              width: double.infinity,
                              child: Row(
                                children: [
                                  Text(
                                    "注册",
                                    style: TextStyle(
                                        fontSize: 26,
                                        color: Colors.red,
                                        fontWeight: FontWeight.bold),
                                  ),
                                  Text(
                                    "账号",
                                    style: TextStyle(
                                        fontSize: 26,
                                        fontWeight: FontWeight.bold),
                                  )
                                ],
                              ),
                            ),
                            SizedBox(
                              height: 5,
                            ),
                            SizedBox(
                              child: Text(
                                "请输入手机号，收取验证码并设置密码",
                                style: TextStyle(
                                    fontSize: 15, color: Color(0xff666666)),
                              ),
                            )
                          ],
                        )),
                    Expanded(
                        child: SingleChildScrollView(
                      physics: const AlwaysScrollableScrollPhysics(),
                      child: Column(
                        children: [
                          buildContainer(
                              child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [buildTitle(title: "手机号")],
                          )),
                          buildContainer(
                              child: CupertinoTextFormFieldRow(
                            padding: const EdgeInsets.only(left: 0, right: 0),
                            style: const TextStyle(fontSize: 18),
                            // controller: controller.loginPhoneInputController,
                            inputFormatters: [
                              FilteringTextInputFormatter.digitsOnly,
                              LengthLimitingTextInputFormatter(11), //限制长度
                            ],
                            placeholder: '请输入手机号',
                            placeholderStyle: TextStyle(
                                color: CupertinoColors.darkBackgroundGray
                                    .withOpacity(.7)),
                            keyboardType: TextInputType.emailAddress,
                            keyboardAppearance: Brightness.dark,
                            onChanged: (value) {
                              state.registerPhone.value = value.toString();
                            },
                          )),
                          buildContainer(
                              child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [buildTitle(title: "验证码")],
                          )),
                          buildContainer(
                            child: Stack(
                              alignment: Alignment.topRight,
                              children: [
                                CupertinoTextFormFieldRow(
                                  padding:
                                      const EdgeInsets.only(left: 0, right: 0),
                                  style: const TextStyle(fontSize: 18),
                                  inputFormatters: [
                                    FilteringTextInputFormatter.digitsOnly,
                                    LengthLimitingTextInputFormatter(6), //限制长度
                                  ],
                                  placeholder: '验证码',
                                  placeholderStyle: TextStyle(
                                      color: CupertinoColors.darkBackgroundGray
                                          .withOpacity(.7)),
                                  keyboardType: TextInputType.emailAddress,
                                  keyboardAppearance: Brightness.dark,
                                  onChanged: (value) => {
                                    state.registerCode.value = value.toString()
                                  },
                                ),
                                Container(
                                  padding: const EdgeInsets.only(right: 30),
                                  child: OutlinedButton(
                                      onPressed: () => {
                                            getRegisterCode(
                                                sendRegisterCodeAPI:
                                                    sendRegisterCodeAPI)
                                          },
                                      style: ButtonStyle(
                                        side: MaterialStateProperty.all(
                                            const BorderSide(
                                                width: 0.0,
                                                color: Colors.transparent)),
                                        shape: MaterialStateProperty.all(
                                            RoundedRectangleBorder(
                                                borderRadius:
                                                    BorderRadius.circular(20))),
                                        textStyle: MaterialStateProperty.all(
                                            const TextStyle(fontSize: 18)),
                                      ),
                                      child: Obx(() => Text(
                                            state.registerWaitTitle.value,
                                            style: const TextStyle(
                                              color: Colors.red,
                                            ),
                                          ))),
                                )
                              ],
                            ),
                          ),
                          buildContainer(
                              child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [buildTitle(title: "密码")],
                          )),
                          buildContainer(
                              child: CupertinoTextFormFieldRow(
                            padding: const EdgeInsets.only(left: 0, right: 0),
                            style: const TextStyle(fontSize: 18),
                            obscureText: true,
                            placeholder: '*密码',
                            placeholderStyle: TextStyle(
                                color: CupertinoColors.darkBackgroundGray
                                    .withOpacity(.7)),
                            keyboardType: TextInputType.emailAddress,
                            keyboardAppearance: Brightness.dark,
                            onChanged: (value) => {
                              state.registerPassword.value = value.toString()
                            },
                          )),
                          buildContainer(
                              child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [buildTitle(title: "确认密码")],
                          )),
                          buildContainer(
                              child: CupertinoTextFormFieldRow(
                            padding: const EdgeInsets.only(left: 0, right: 0),
                            style: const TextStyle(fontSize: 18),
                            obscureText: true,
                            placeholder: '*确认密码',
                            placeholderStyle: TextStyle(
                                color: CupertinoColors.darkBackgroundGray
                                    .withOpacity(.7)),
                            keyboardType: TextInputType.emailAddress,
                            keyboardAppearance: Brightness.dark,
                            onChanged: (value) => {
                              state.registerAgainPassword.value =
                                  value.toString()
                            },
                          )),
                          buildContainer(
                              child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [buildTitle(title: "邀请码")],
                          )),
                          buildContainer(
                            child: CupertinoTextFormFieldRow(
                              padding: const EdgeInsets.only(left: 0, right: 0),
                              style: const TextStyle(fontSize: 18),
                              inputFormatters: [
                                FilteringTextInputFormatter.digitsOnly,
                                LengthLimitingTextInputFormatter(11), //限制长度
                              ],
                              placeholder: '邀请码（选填）',
                              placeholderStyle: TextStyle(
                                  color: CupertinoColors.darkBackgroundGray
                                      .withOpacity(.7)),
                              keyboardType: TextInputType.emailAddress,
                              keyboardAppearance: Brightness.dark,
                              onChanged: (value) => {
                                state.registerInviteCode.value =
                                    value.toString()
                              },
                            ),
                          ),
                          buildContainer(
                              child: buildButton(
                                  title: "注册",
                                  height: 60,
                                  borderRadius: 5,
                                  onClick: () {
                                    //检查同意按钮
                                    var isRead = state.isRead.value;
                                    if (!isRead) {
                                      EasyLoading.showToast("请勾选同意按钮");
                                      return;
                                    }
                                    handleRegister(
                                        appType: appType,
                                        loginAPI: loginAPI,
                                        loginSuccess: loginSuccess,
                                        registerAPI: registerAPI);
                                  },
                                  colors: [
                                const Color(0xffe53627),
                                const Color(0xffe53627)
                              ])),
                          buildRadio(
                            appType: appType,
                            requestBaseUrl: requestBaseUrl,
                          ),
                          SizedBox(
                            height: 30,
                          )
                        ],
                      ),
                    )),
                  ],
                ))));
  }

  // 选用户同意书视图
  Widget buildRadio({String appType = 'user', String requestBaseUrl = ''}) {
    var privateName = 'private';
    var serviceName = 'service';
    if (appType == 'supplier') {
      privateName = 'private-supply';
      serviceName = 'service-supply';
    }
    if (appType == 'business') {
      privateName = 'private-business';
      serviceName = 'service-business';
    }
    if (appType == 'worker') {
      privateName = 'private-worker';
      serviceName = 'service-worker';
    }
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Expanded(
          flex: 1,
          child: Wrap(
            alignment: WrapAlignment.center,
            crossAxisAlignment: WrapCrossAlignment.center,
            direction: Axis.horizontal,
            children: [
              Obx(() => Checkbox(
                    value: state.isRead.value,
                    onChanged: (v) {
                      changeRead();
                    },
                    activeColor: Colors.black,
                  )),
              const Text("已阅读并同意:"),
              GestureDetector(
                onTap: () {
                  Get.toNamed("/webview", arguments: {
                    "title": "《隐私政策》",
                    "url": "${requestBaseUrl}/download/${privateName}.html"
                  });
                },
                child: const Text(
                  "《隐私政策》",
                  style: TextStyle(color: Color(0xff2C65FF)),
                ),
              ),
              GestureDetector(
                onTap: () {
                  Get.toNamed("/webview", arguments: {
                    "title": "《用户协议》",
                    "url": "${requestBaseUrl}/download/${serviceName}.html"
                  });
                },
                child: const Text(
                  "《用户协议》",
                  style: TextStyle(color: Color(0xff2C65FF)),
                ),
              ),
              Visibility(
                  visible: appType != 'user',
                  child: GestureDetector(
                    onTap: () {
                      Get.toNamed("/webview", arguments: {
                        "title": "《入驻协议》",
                        "url": "${requestBaseUrl}/download/service-join.html"
                      });
                    },
                    child: const Text(
                      "《入驻协议》",
                      style: TextStyle(color: Color(0xff2C65FF)),
                    ),
                  )),
              GestureDetector(
                onTap: () {
                  Get.toNamed("/webview", arguments: {
                    "title": "《开放平台在线服务协议》",
                    "url": "${requestBaseUrl}/download/open-service.html"
                  });
                },
                child: const Text(
                  "《开放平台在线服务协议》",
                  style: TextStyle(color: Color(0xff2C65FF)),
                ),
              ),
            ],
          ),
        )
      ],
    );
  }

  openFindPassword(
      {required BuildContext context,
      required String appType,
      required Function({String code, String password, String userAccount})
          findPasswordAPI,
      required Function loginSuccess,
      required Function registerAPI,
      required Function({String userAccount, String userType})
          rejectAndRegisterAPI,
      required dynamic Function({String mobile}) sendRegisterCodeAPI,
      required Function({String userAccount, String password}) loginAPI,
      required Function({String mobile}) sendFindCodeAPI}) {
    Get.bottomSheet(
        isScrollControlled: true,
        SizedBox(
            height: double.infinity,
            child: Container(
              width: double.infinity,
              height: double.infinity,
              color: Colors.white,
              child: Column(
                children: [
                  buildBanner(
                      context: context,
                      hasBack: true,
                      solt: const Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox(
                            width: double.infinity,
                            child: Row(
                              children: [
                                Text(
                                  "忘记",
                                  style: TextStyle(
                                      fontSize: 26,
                                      color: Colors.red,
                                      fontWeight: FontWeight.bold),
                                ),
                                Text(
                                  "密码",
                                  style: TextStyle(
                                      fontSize: 26,
                                      fontWeight: FontWeight.bold),
                                )
                              ],
                            ),
                          ),
                          SizedBox(
                            height: 5,
                          ),
                          SizedBox(
                            child: Text(
                              "请输入手机号，收取验证码并设置新密码",
                              style: TextStyle(
                                  fontSize: 15, color: Color(0xff666666)),
                            ),
                          )
                        ],
                      )),
                  Expanded(
                      child: SingleChildScrollView(
                          physics: const AlwaysScrollableScrollPhysics(),
                          child: Column(
                            children: [
                              buildContainer(
                                  child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [buildTitle(title: "手机号")],
                              )),
                              buildContainer(
                                  child: CupertinoTextFormFieldRow(
                                padding:
                                    const EdgeInsets.only(left: 0, right: 0),
                                style: const TextStyle(fontSize: 18),
                                inputFormatters: [
                                  FilteringTextInputFormatter.digitsOnly,
                                  LengthLimitingTextInputFormatter(11), //限制长度
                                ],
                                placeholder: '手机号',
                                placeholderStyle: TextStyle(
                                    color: CupertinoColors.darkBackgroundGray
                                        .withOpacity(.7)),
                                keyboardType: TextInputType.emailAddress,
                                keyboardAppearance: Brightness.dark,
                                onChanged: (value) =>
                                    {state.findPhone.value = value.toString()},
                              )),
                              buildContainer(
                                  child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [buildTitle(title: "验证码")],
                              )),
                              buildContainer(
                                  child: Stack(
                                alignment: Alignment.topRight,
                                children: [
                                  CupertinoTextFormFieldRow(
                                    padding: const EdgeInsets.only(
                                        left: 0, right: 0),
                                    style: const TextStyle(fontSize: 18),
                                    inputFormatters: [
                                      FilteringTextInputFormatter.digitsOnly,
                                      LengthLimitingTextInputFormatter(
                                          6), //限制长度
                                    ],
                                    placeholder: '验证码',
                                    placeholderStyle: TextStyle(
                                        color: CupertinoColors
                                            .darkBackgroundGray
                                            .withOpacity(.7)),
                                    keyboardType: TextInputType.emailAddress,
                                    keyboardAppearance: Brightness.dark,
                                    onChanged: (value) => {
                                      state.findCode.value = value.toString()
                                    },
                                  ),
                                  Container(
                                    padding: const EdgeInsets.only(right: 30),
                                    child: OutlinedButton(
                                        onPressed: () => {
                                              getFindCode(
                                                  sendFindCodeAPI:
                                                      sendFindCodeAPI)
                                            },
                                        style: ButtonStyle(
                                          side: MaterialStateProperty.all(
                                              const BorderSide(
                                                  width: 0.0,
                                                  color: Colors.transparent)),
                                          shape: MaterialStateProperty.all(
                                              RoundedRectangleBorder(
                                                  borderRadius:
                                                      BorderRadius.circular(
                                                          20))),
                                          textStyle: MaterialStateProperty.all(
                                              const TextStyle(fontSize: 18)),
                                        ),
                                        child: Obx(() => Text(
                                              state.findWaitTitle.value,
                                              style: const TextStyle(
                                                color: Colors.red,
                                              ),
                                            ))),
                                  )
                                ],
                              )),
                              buildContainer(
                                  child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [buildTitle(title: "密码")],
                              )),
                              buildContainer(
                                  child: CupertinoTextFormFieldRow(
                                padding:
                                    const EdgeInsets.only(left: 0, right: 0),
                                style: const TextStyle(fontSize: 18),
                                obscureText: true,
                                placeholder: '*新密码',
                                placeholderStyle: TextStyle(
                                    color: CupertinoColors.darkBackgroundGray
                                        .withOpacity(.7)),
                                keyboardType: TextInputType.emailAddress,
                                keyboardAppearance: Brightness.dark,
                                onChanged: (value) => {
                                  state.findNewPassword.value = value.toString()
                                },
                              )),
                              buildContainer(
                                  child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [buildTitle(title: "确认密码")],
                              )),
                              buildContainer(
                                  child: CupertinoTextFormFieldRow(
                                padding:
                                    const EdgeInsets.only(left: 0, right: 0),
                                style: const TextStyle(fontSize: 18),
                                obscureText: true,
                                placeholder: '*确认新密码',
                                placeholderStyle: TextStyle(
                                    color: CupertinoColors.darkBackgroundGray
                                        .withOpacity(.7)),
                                keyboardType: TextInputType.emailAddress,
                                keyboardAppearance: Brightness.dark,
                                onChanged: (value) => {
                                  state.findAgainNewPassword.value =
                                      value.toString()
                                },
                              )),
                              buildContainer(
                                  child: buildButton(
                                      title: "确定",
                                      height: 60,
                                      borderRadius: 5,
                                      onClick: () {
                                        handleFindPassword(
                                            context: context,
                                            registerAPI: registerAPI,
                                            sendRegisterCodeAPI:
                                                sendRegisterCodeAPI,
                                            rejectAndRegisterAPI:
                                                rejectAndRegisterAPI,
                                            appType: appType,
                                            loginAPI: loginAPI,
                                            loginSuccess: loginSuccess,
                                            findPasswordAPI: findPasswordAPI);
                                      },
                                      colors: [
                                    const Color(0xffe53627),
                                    const Color(0xffe53627)
                                  ]))
                            ],
                          )))
                ],
              ),
            )));
  }

  handleOrcData({String imageType = '', dynamic orcData}) {
    if (orcData == null) {
      return;
    }
    if (imageType == "BusinessLicense") {
      var creditCode = showText(orcData["creditCode"]);
      var businessAddress = showText(orcData["businessAddress"]);

      var companyName = showText(orcData["companyName"]);

      var legalPerson = showText(orcData["legalPerson"]);

      if (creditCode.isNotEmpty) {
        registerCertificateCodeInputController.text = creditCode;
        state.registerCertificateCode.value = creditCode;
      }

      if (companyName.isNotEmpty) {
        registerStoreNameInputController.text = companyName;
        state.registerStoreName.value = companyName;
        state.registerSupplierName.value = companyName;
      }

      if (businessAddress.isNotEmpty) {
        registerAddressInputController.text = businessAddress;

        state.registerAddress.value = businessAddress;
      }

      if (legalPerson.isNotEmpty) {
        registerUserNameInputController.text = legalPerson;
        state.registerUserName.value = legalPerson;
      }
    }
    if (imageType == "VehicleLicense") {
      var licensePlateNumber = showText(orcData["licensePlateNumber"]);
      if (licensePlateNumber.isNotEmpty) {
        registerCarNumberInputController.text = licensePlateNumber;
        state.registerCarNumber.value = licensePlateNumber;
      }
    }
    if (imageType == "DrivingLicense") {
      var name = showText(orcData["name"]);

      if (name.isNotEmpty) {
        registerDriverNameInputController.text = name;

        state.registerDriverName.value = name;
      }
    }
    if (imageType == "IdCard") {
      var name = showText(orcData["name"]);
      var idNumber = showText(orcData["idNumber"]);

      if (idNumber.isNotEmpty) {
        registerIdNumberInputController.text = idNumber;

        state.registerIdNumber.value = idNumber;
      }

      if (name.isNotEmpty) {
        registerUserNameInputController.text = name;

        state.registerUserName.value = name;
      }
    }
  }

  //处理注册逻辑
  void handleRegister(
      {required String appType,
      required Function registerAPI,
      required Function loginSuccess,
      required Function({String userAccount, String password})
          loginAPI}) async {
    if (appType == 'user') {
      var userAccount = state.registerPhone.value;
      var password = state.registerPassword.value;
      var code = state.registerCode.value;
      var againPassword = state.registerAgainPassword.value;
      var inviteCode = state.registerInviteCode.value;
      if (userAccount.isEmpty) {
        EasyLoading.showToast("请输入手机号");
        return;
      }
      if (code.isEmpty) {
        EasyLoading.showToast("请输入验证码");
        return;
      }
      if (password.isEmpty) {
        EasyLoading.showToast("请输入密码");
        return;
      }
      if (password != againPassword) {
        EasyLoading.showToast("两次密码输入不一致");
        return;
      }

      var res = await registerAPI(
          code: code,
          userAccount: userAccount,
          password: password,
          inviteCode: inviteCode);

      if (res) {
        EasyLoading.showSuccess("注册成功");
        Get.back();
        //切换登录面板
        // state.activeTab.value = 1;
        //输入登录手机号
        state.loginPhone.value = userAccount;
        loginPhoneInputController.text = userAccount;
        // 延时1s执行返回
        Future.delayed(const Duration(seconds: 2), () {
          Get.back();
          // handleLogin(loginSuccess: loginSuccess, loginAPI: loginAPI);
        });
      }
    }

    if (appType == 'business') {
      var userAccount = state.registerPhone.value;
      var password = state.registerPassword.value;
      var code = state.registerCode.value;
      var againPassword = state.registerAgainPassword.value;
      var inviteCode = state.registerInviteCode.value;
      var idNumber = state.registerIdNumber.value;
      var idNumberImages = state.registerIdNumberImages.value;
      var storeImageUrl = state.registerStoreImageUrl.value;
      var userName = state.registerUserName.value;
      var address = state.registerAddress.value;
      var storeName = state.registerStoreName.value;

      var businessImages = state.registerBusinessImages.value;

      // var businessCertificateFrontUrl =
      //     state.registerBusinessCertificateFrontUrl.value;
      // var businessCertificateReverseUrl =
      //     state.registerBusinessCertificateReverseUrl.value;
      var certificateCode = state.registerCertificateCode.value;
      // if (businessImages.isEmpty) {
      //   EasyLoading.showToast("请上传营业执照/开户许可证/一般纳税人");
      //   return;
      // }
      if (certificateCode.isEmpty) {
        EasyLoading.showToast("请输入统一社会信用代码");
        return;
      }
      if (storeName.isEmpty) {
        EasyLoading.showToast("请输入公司/店面名称");
        return;
      }
      if (address.isEmpty) {
        EasyLoading.showToast("请输入公司/店面地址");
        return;
      }

      if (idNumber.isEmpty) {
        EasyLoading.showToast("请输入身份证");
        return;
      }
      // if (idNumberImages.isEmpty) {
      //   EasyLoading.showToast("请上传身份证照片");
      //   return;
      // }
      if (userName.isEmpty) {
        EasyLoading.showToast("请输入法人名称");
        return;
      }

      if (storeImageUrl.isEmpty) {
        EasyLoading.showToast("请上传公司/店铺图片");
        return;
      }

      if (userAccount.isEmpty) {
        EasyLoading.showToast("请输入手机号");
        return;
      }

      if (code.isEmpty) {
        EasyLoading.showToast("请输入验证码");
        return;
      }
      if (password.isEmpty) {
        EasyLoading.showToast("请输入密码");
        return;
      }
      if (password != againPassword) {
        EasyLoading.showToast("两次密码输入不一致");
        return;
      }

      var res = await registerAPI(
          code: code,
          userAccount: userAccount,
          password: password,
          businessImages: businessImages.join(","),
          // businessCertificateFrontUrl: businessCertificateFrontUrl.join(","),
          // businessCertificateReverseUrl:
          //     businessCertificateReverseUrl.join(","),
          certificateCode: certificateCode,
          idNumber: idNumber,
          idNumberImages: idNumberImages.join(","),
          userName: userName,
          address: address,
          storeName: storeName,
          storeImageUrl: storeImageUrl.join(","),
          inviteCode: inviteCode);

      if (res) {
        EasyLoading.showSuccess("注册成功");
        //切换登录面板
        // state.activeTab.value = 1;
        //输入登录手机号
        state.loginPhone.value = userAccount;
        loginPhoneInputController.text = userAccount;
        // 延时1s执行返回
        Future.delayed(const Duration(seconds: 2), () {
          Get.back();
          Get.back();
          // handleLogin(loginSuccess: loginSuccess, loginAPI: loginAPI);
        });
      }
    }

    if (appType == 'worker') {
      var idNumber = state.registerIdNumber.value;
      var idNumberImages = state.registerIdNumberImages.value;
      var userName = state.registerUserName.value;
      var driveImages = state.registerDriveImages.value;
      var carNumber = state.registerCarNumber.value;
      var driverName = state.registerDriverName.value;
      var userAccount = state.registerPhone.value;
      var password = state.registerPassword.value;
      var code = state.registerCode.value;
      var againPassword = state.registerAgainPassword.value;
      var inviteCode = state.registerInviteCode.value;

      var carCertImages = state.registerCarCertImages.value;

      // if (idNumberImages.isEmpty) {
      //   EasyLoading.showToast("请上传身份改正反面");
      //   return;
      // }
      if (userName.isEmpty) {
        EasyLoading.showToast("请输入身份证姓名");
        return;
      }
      if (idNumber.isEmpty) {
        EasyLoading.showToast("请输入身份证号码");
        return;
      }

      if (carCertImages.isEmpty) {
        EasyLoading.showToast("请上传驾驶证");
        return;
      }

      if (driverName.isEmpty) {
        EasyLoading.showToast("请输入驾驶证姓名");
        return;
      }

      if (driveImages.isEmpty) {
        EasyLoading.showToast("请上传行驶证/流动服务车照片");
        return;
      }

      if (carNumber.isEmpty) {
        EasyLoading.showToast("请输入服务车车牌");
        return;
      }

      if (userAccount.isEmpty) {
        EasyLoading.showToast("请输入手机号");
        return;
      }
      if (code.isEmpty) {
        EasyLoading.showToast("请输入验证码");
        return;
      }
      if (password.isEmpty) {
        EasyLoading.showToast("请输入密码");
        return;
      }
      if (password != againPassword) {
        EasyLoading.showToast("两次密码输入不一致");
        return;
      }

      var res = await registerAPI(
          code: code,
          idNumberImages: idNumberImages.join(","),
          userName: userName,
          idNumber: idNumber,
          driveImages: driveImages.join(","),
          carNumber: carNumber,
          driverName: driverName,
          userAccount: userAccount,
          password: password,
          carCertImages: carCertImages.join(","),
          inviteCode: inviteCode);

      if (res) {
        EasyLoading.showSuccess("注册成功");
        //切换登录面板
        // state.activeTab.value = 1;
        //输入登录手机号
        state.loginPhone.value = userAccount;
        loginPhoneInputController.text = userAccount;
        // 延时1s执行返回
        Future.delayed(const Duration(seconds: 2), () {
          Get.back();
          Get.back();
          // handleLogin(loginSuccess: loginSuccess, loginAPI: loginAPI);
        });
      }
    }

    if (appType == 'supplier') {
      var userAccount = state.registerPhone.value;
      var password = state.registerPassword.value;
      var code = state.registerCode.value;
      var againPassword = state.registerAgainPassword.value;
      var inviteCode = state.registerInviteCode.value;
      var idNumber = state.registerIdNumber.value;
      var idNumberImages = state.registerIdNumberImages.value;
      // var storeImageUrl = state.registerStoreImageUrl.value;
      var userName = state.registerUserName.value;
      var address = state.registerAddress.value;
      // var storeName = state.registerStoreName.value;
      var supplierName = state.registerSupplierName.value;

      var businessImages = state.registerBusinessImages.value;
      var certImages = state.registerCertImages.value;

      // var businessCertificateFrontUrl =
      //     state.registerBusinessCertificateFrontUrl.value;
      // var businessCertificateReverseUrl =
      //     state.registerBusinessCertificateReverseUrl.value;
      var certificateCode = state.registerCertificateCode.value;
      // if (businessImages.isEmpty) {
      //   EasyLoading.showToast("请上传营业执照/开户许可证/一般纳税人");
      //   return;
      // }

      if (idNumber.isEmpty) {
        EasyLoading.showToast("请输入身份证");
        return;
      }

      if (address.isEmpty) {
        EasyLoading.showToast("请输入公司/店面地址");
        return;
      }
      if (certImages.isEmpty) {
        EasyLoading.showToast("请上传品牌证书/代理证明");
        return;
      }
      // if (idNumberImages.isEmpty) {
      //   EasyLoading.showToast("请上传身份证照片");
      //   return;
      // }
      if (userName.isEmpty) {
        EasyLoading.showToast("请输入法人名称");
        return;
      }
      if (supplierName.isEmpty) {
        EasyLoading.showToast("请输入供应商名称");
        return;
      }
      if (userAccount.isEmpty) {
        EasyLoading.showToast("请输入手机号");
        return;
      }
      // if (storeName.isEmpty) {
      //   EasyLoading.showToast("请输入店铺名称");
      //   return;
      // }
      // if (storeImageUrl.isEmpty) {
      //   EasyLoading.showToast("请上传店铺图片");
      //   return;
      // }

      if (code.isEmpty) {
        EasyLoading.showToast("请输入验证码");
        return;
      }
      if (password.isEmpty) {
        EasyLoading.showToast("请输入密码");
        return;
      }
      if (password != againPassword) {
        EasyLoading.showToast("两次密码输入不一致");
        return;
      }

      var res = await registerAPI(
          code: code,
          userAccount: userAccount,
          password: password,
          businessImages: businessImages.join(","),
          // businessCertificateFrontUrl: businessCertificateFrontUrl.join(","),
          // businessCertificateReverseUrl:
          //     businessCertificateReverseUrl.join(","),
          certificateCode: certificateCode,
          idNumber: idNumber,
          idNumberImages: idNumberImages.join(","),
          userName: userName,
          address: address,
          supplierName: supplierName,
          certImages: certImages.join(","),
          // storeName: storeName,
          // storeImageUrl: storeImageUrl.join(","),
          inviteCode: inviteCode);

      if (res) {
        EasyLoading.showSuccess("注册成功");
        //切换登录面板
        // state.activeTab.value = 1;
        //输入登录手机号
        state.loginPhone.value = userAccount;
        state.registerBusinessCertificateFrontUrl.value = [];
        state.registerBusinessCertificateReverseUrl.value = [];
        state.registerStoreImageUrl.value = [];
        state.registerIdCardImage.value = [];
        loginPhoneInputController.text = userAccount;
        resetRegisterInfo();
        Get.back();
        Get.back();
        // 延时1s执行返回
        Future.delayed(const Duration(seconds: 2), () {
          Get.back();
          Get.back();
          // handleLogin(loginSuccess: loginSuccess, loginAPI: loginAPI);
        });
      }
    }
  }

  //发送注册验证码
  void getRegisterCode(
      {required Function({String mobile}) sendRegisterCodeAPI}) async {
    if (state.registerWaiting.value) {
      return;
    }
    if (state.registerPhone.value == "") {
      EasyLoading.showError('请输入手机号！');
      return;
    }

    var data = await sendRegisterCodeAPI(mobile: state.registerPhone.value);
    EasyLoading.showToast("发送成功");
    //进入等待
    registerLoopTimer();
  }

  //注册验证码等待
  void registerLoopTimer() {
    int count = 60;
    const period = Duration(seconds: 1);
    state.registerLoop = Timer.periodic(period, (timer) {
      state.registerWaiting.value = true;
      count--;
      if (count < 0) {
        //取消定时器，避免无限回调
        timer.cancel();
        state.registerWaiting.value = false;
        state.registerWaitTitle.value = "重新获取";
        return;
      }
      state.registerWaitTitle.value = "重新获取(${count.toString()}s)";
    });
  }

  //处理找回密码逻辑
  void handleFindPassword(
      {required BuildContext context,
      required String appType,
      required Function registerAPI,
      required dynamic Function({String mobile}) sendRegisterCodeAPI,
      required Function({String userAccount, String userType})
          rejectAndRegisterAPI,
      required Function({String code, String password, String userAccount})
          findPasswordAPI,
      Function? findPasswordSuccess,
      required Function loginSuccess,
      required Function({String userAccount, String password})
          loginAPI}) async {
    var userAccount = state.findPhone.value;
    var password = state.findNewPassword.value;
    var againPassword = state.findAgainNewPassword.value;
    var code = state.findCode.value;

    if (userAccount.isEmpty) {
      EasyLoading.showToast("请输入手机号");
      return;
    }
    if (password.isEmpty) {
      EasyLoading.showToast("请输入新密码");
      return;
    }
    if (code.isEmpty) {
      EasyLoading.showToast("请输入验证码");
      return;
    }
    if (password != againPassword) {
      EasyLoading.showToast("两次输入的密码不一致");
      return;
    }
    var data = await findPasswordAPI(
        code: code, password: password, userAccount: userAccount);
    // //直接去登录
    state.loginPhone.value = userAccount;
    state.loginPassword.value = password;
    state.isRead.value = true;
    EasyLoading.showToast("处理成功");
    Get.back();
    //进行登录操作逻辑
    handleLogin(
        context: context,
        appType: appType,
        registerAPI: registerAPI,
        rejectAndRegisterAPI: rejectAndRegisterAPI,
        sendRegisterCodeAPI: sendRegisterCodeAPI,
        loginSuccess: loginSuccess,
        loginAPI: loginAPI);
    // findPasswordSuccess();
    // var res = await loginAPI(userAccount: userAccount, password: password);
    // handleLogin();
  }

  //发送找回密码验证码
  void getFindCode({required Function({String mobile}) sendFindCodeAPI}) async {
    if (state.findWaiting.value) {
      return;
    }
    if (state.findPhone.value == "") {
      EasyLoading.showError('请输入手机号！');
      return;
    }

    var data = await sendFindCodeAPI(mobile: state.findPhone.value);
    EasyLoading.showToast("发送成功");
    //进入等待
    findLoopTimer();
  }

  //找回密码验证码等待
  void findLoopTimer() {
    int count = 60;
    const period = Duration(seconds: 1);
    state.findLoop = Timer.periodic(period, (timer) {
      state.findWaiting.value = true;
      count--;
      if (count < 0) {
        //取消定时器，避免无限回调
        timer.cancel();
        state.findWaiting.value = false;
        state.findWaitTitle.value = "重新获取";
        return;
      }
      state.findWaitTitle.value = "重新获取(${count.toString()}s)";
    });
  }
}
